<?php
class moveto_first_step
{
	public $booking_date;
	public $source_city;
	public $via_city;
	public $destination_city;
	public $user_detail;
	public $move_size;
	public $first_step_data;
	public $next_order_id;
	public $reg_date;
	public $orderID;
	public $clientID;

	function get_off_days()
    {
        global $wpdb;
		
        $offdays = $wpdb->get_results("SELECT * FROM ".$wpdb->prefix."mp_schedule_dayoffs");
       
	   return $offdays;
    }
   function insert_first_step_data()
    {
global $wpdb;	

	$check=$wpdb->get_row("SELECT * FROM ".$wpdb->prefix."users WHERE user_email = '".$this->first_step_data['email']."'");
	if(empty($check)){
		
		if($this->first_step_data['moveto_allow_user_login'] == "E"){
			$insert_wp_user = $wpdb->query("INSERT INTO ".$wpdb->prefix."users (`user_login`,`user_pass`, `user_nicename`, `user_email`, `user_registered`,`display_name`) VALUES ('".$this->first_step_data['name']."','".md5($this->first_step_data['cust_password'])."','".$this->first_step_data['name']."','".$this->first_step_data['email']."','".$this->reg_date."','".$this->first_step_data['name']."')");
		}else{
			$insert_wp_user = $wpdb->query("INSERT INTO ".$wpdb->prefix."users (`user_login`, `user_nicename`, `user_email`, `user_registered`,`display_name`) VALUES ('".$this->first_step_data['name']."','".$this->first_step_data['name']."','".$this->first_step_data['email']."','".$this->reg_date."','".$this->first_step_data['name']."')");
		}
		
		$last_id_inserted = $wpdb->insert_id;
		
		add_user_meta($last_id_inserted,'phone',$this->first_step_data['phone']);
		add_user_meta($last_id_inserted,'country_code',$this->first_step_data['country_code']);
		
		$user = new WP_User( $last_id_inserted );	
		$user->set_role( 'subscriber' );
	}else{
		$last_id_inserted = $check->ID;
	}
	$insert_first_step_data1 = $wpdb->query("INSERT INTO ".$wpdb->prefix .'mp_order_client_info'." (`order_id`,`client_name`,`client_email`,`client_phone`,`client_personal_info`)values('".$this->next_order_id."','".$this->first_step_data['name']."','".$this->first_step_data['email']."','".$this->first_step_data['phone']."','')");
	
if($insert_first_step_data1){

	
$insert_first_step_data2 = $wpdb->query("INSERT INTO ".$wpdb->prefix .'mp_bookings'." (`order_id`,`client_id`,`source_city`,`via_city`,`destination_city`,`move_size`,`booking_date`,`date_period`,`user_info`,`booking_status`)values('".$this->next_order_id."','".$last_id_inserted."','".$this->source_city."','".$this->via_city."','".$this->destination_city."','".$this->move_size."','".$this->booking_date."','".$this->date_period."','".$this->user_detail."','P')");

if($insert_first_step_data2){
$last_id_inserted2 = $wpdb->insert_id;



return $last_id_inserted2;
}
}
}
   function update_first_step_data()
    {
global $wpdb;	

$wpdb->query("UPDATE ".$wpdb->prefix."users SET `user_login` = '".$this->first_step_data['name']."',  `user_nicename` = '".$this->first_step_data['name']."', `user_email` = '".$this->first_step_data['email']."', `display_name` = '".$this->first_step_data['name']."' WHERE `ID` = '".$this->clientID."'"); 

$wpdb->query("UPDATE `".$wpdb->prefix."mp_order_client_info` SET `client_name` = '".$this->first_step_data['name']."', `client_email` = '".$this->first_step_data['email']."',`client_phone` = '".$this->first_step_data['phone']."' WHERE `order_id` = '".$this->orderID."'");


$wpdb->query("UPDATE `".$wpdb->prefix ."mp_bookings` SET `source_city` = '".$this->source_city."',`via_city` = '".$this->via_city."',`destination_city` = '".$this->destination_city."',`move_size` = '".$this->move_size."',`booking_date` = '".$this->booking_date."',`date_period` = '".$this->date_period."',`user_info` = '".$this->user_detail."' WHERE `order_id` = '".$this->orderID."'");

}

   
	
}
?>